package com.hyving.summer.fxboot.ctrl;

import com.hyving.summer.fxboot.model.GoodsNameTableView;
import de.felixroske.jfxsupport.FXMLController;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.Initializable;
import javafx.scene.chart.*;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.Pane;
import lombok.extern.slf4j.Slf4j;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

@Slf4j
@FXMLController
public class StaticCtrl  implements Initializable {

    public Pane rootPane;

    public TableView<GoodsNameTableView> table;

    public TableView goodsTable;

    public TableColumn goodsName;

    public PieChart pie;
    public LineChart line;

    public CategoryAxis xSide;

    public NumberAxis ySide;


    public void initialize(URL location, ResourceBundle resources) {
        log.info("initialize: {}", location.getPath());
        defaultData();
    }

    public void defaultData(){

//        ObservableList<GoodsNameTableView> goodsNameList = getAllGoodsNameOrdered(file);
        ObservableList<GoodsNameTableView> goodsNameList =null;

        goodsName.setCellValueFactory(new PropertyValueFactory<GoodsNameTableView,String>("goodsName"));

        table.setItems(goodsNameList);

        ObservableList<PieChart.Data> pieChartData
                = FXCollections.observableArrayList(
                new PieChart.Data("Apache", 52),
                new PieChart.Data("Nginx", 31),
                new PieChart.Data("IIS", 12),
                new PieChart.Data("LiteSpeed", 2),
                new PieChart.Data("Google server", 1),
                new PieChart.Data("Others", 2));

        pie.getData().addAll(pieChartData);
        pie.setTitle("Web servers market share (2016)");

//        line.setTitle("");
        xSide.setLabel("Time");
        ySide.setLabel("数量");

        XYChart.Series data = new XYChart.Series();

        data.getData().add(new XYChart.Data("2004", 2));
        data.getData().add(new XYChart.Data("2005", 26));
        data.getData().add(new XYChart.Data("2006", 7));
        data.getData().add(new XYChart.Data("2007", 16));
        data.getData().add(new XYChart.Data("2008", 59));
        data.getData().add(new XYChart.Data("2009", 91));
        data.getData().add(new XYChart.Data("2010", 72));
        data.getData().add(new XYChart.Data("2011", 75));
        data.getData().add(new XYChart.Data("2012", 37));
        data.getData().add(new XYChart.Data("2013", 1));

        line.getData().add(data);

    }


}
